// pages/subrogation/debtInfo/index.js
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        parameter: {
            'navbar': '1',
            'return': '1',
            'title': '垫付金额详情',
            'color': true,
            'class': false
        },
        pageH: app.globalData.pageHeight,
        selectMoney: 1,
        selectDay: 1,
        order: 3,
        pageNum: 1,
        salesmanId: wx.getStorageSync('userInfo').id
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        // this.getHeight1()
        // this.orderInfo()
        // this.findReminder()
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getHeight1()
        this.orderInfo()
        this.findReminder()
    },

    /* 店铺欠款详情 */
    orderInfo(e) {
        var that = this,
            pageNum = 1,
            list = [];
        // /bdb/WorkerBee/paymentMoneyDetailsList
        app.baseGet(app.U({
            m: 'bdservice/bdb',
            c: 'WorkerBee',
            a: 'paymentMoneyDetailsList',
            q: {
                order: that.data.order,
                pageNum: that.data.pageNum,
                pageSize: 15,
                salesmanId: that.data.salesmanId
            }
        }), (res) => {}, res => {
            pageNum = res.data.pageNum;
            if (pageNum == 1) {
                list = res.data.list;
            } else {
                list = app.SplitArray(res.data.list ? res.data.list : [], that.data.orderList) //分页合并数组
            }
            console.log(list)
            that.setData({
                orderList: list
            })
        })
    },

    /* 垫付金额内容 */
    findReminder(e) {
        var that = this;
        // /bdb/WorkerBee/paymentMoneyDetailsInfo
        app.baseGet(app.U({
            m: 'bdservice/bdb',
            c: 'WorkerBee',
            a: 'paymentMoneyDetailsInfo',
            q: {
                salesmanId: that.data.salesmanId
            }
        }), (res) => {}, res => {
            that.setData({
                money: res.data
            })
        })
    },

    //  获取高度适配列表高度
    getHeight1() {
        var that = this;
        wx.createSelectorQuery().selectAll('.navbar').boundingClientRect().exec(function (res) {
            that.setData({
                listHeight: res[0][0].height
            })
        })
    },

    // 滚动到底部加载更多
    waterLower() {
        var pageNum = Number(this.data.pageNum) + 1;
        this.setData({
            pageNum: pageNum,
        })
        this.orderInfo()
    },

    //金额排序
    selectMoney() {
        this.setData({
            order: this.data.order == 1 ? 2 : 1,
            pageNum: 1,
            scrollTop: 0
        })
        this.orderInfo()
    },

    //欠款天数排序
    selectDay() {
        this.setData({
            order: this.data.order == 3 ? 4 : 3
        })
        this.orderInfo()
    },

    goInfo(e) {
        console.log(e)
        wx.navigateTo({
            url: './info/index?id=' + JSON.stringify(e.currentTarget.dataset.id),
        })
    }
})